package com.xiaoshuidi.cloud.module.contract.api.contract;

import com.xiaoshuidi.cloud.framework.common.pojo.CommonResult;
import com.xiaoshuidi.cloud.framework.common.pojo.PageResult;
import com.xiaoshuidi.cloud.module.contract.api.CustomerCompanyApi;
import com.xiaoshuidi.cloud.module.contract.convert.contract.CustomerCompanyConvert;
import com.xiaoshuidi.cloud.module.contract.dal.dataobject.contract.CustomerCompanyDO;
import com.xiaoshuidi.cloud.module.contract.service.contract.CustomerCompanyService;
import com.xiaoshuidi.cloud.module.contract.vo.CustomerCompanyApiRespVO;
import com.xiaoshuidi.cloud.module.contract.vo.CustomerCompanyPageApiReqVO;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

import static com.xiaoshuidi.cloud.framework.common.pojo.CommonResult.success;
import static com.xiaoshuidi.cloud.module.contract.enums.ApiConstants.VERSION;

/**
 * @Description:
 * @author: zhaoyu
 * @date: 2023/6/25
 */
@Slf4j
@RestController
@Validated
@RequiredArgsConstructor
public class CustomerCompanyApiImpl implements CustomerCompanyApi {

    @Resource
    private CustomerCompanyService customerCompanyService;

    @Override
    public CommonResult<PageResult<CustomerCompanyApiRespVO>> getCustomerCompany(CustomerCompanyPageApiReqVO reqVO) {
        PageResult<CustomerCompanyDO> customerCompanyPage = customerCompanyService.getCustomerCompanyPage(CustomerCompanyConvert.INSTANCE.convert(reqVO));
        return success(CustomerCompanyConvert.INSTANCE.convertApiPage(customerCompanyPage));
    }

    @Override
    public CommonResult<CustomerCompanyApiRespVO> getById(Long id) {
        return success(CustomerCompanyConvert.INSTANCE.convert2(customerCompanyService.getCompanyDoById(id)));
    }
}
